# -*- coding: utf-8 -*-

# Define here the models for your scraped items
#
# See documentation in:
# https://doc.scrapy.org/en/latest/topics/items.html

import scrapy

from scrapy.loader.processors import MapCompose, TakeFirst, Join
from scrapy_gif.utils.common import get_nums


class ScrapyGifItem(scrapy.Item):
    # define the fields for your item here like:
    # name = scrapy.Field()
    pass


class ScrapyListItem(scrapy.Item):
    """
    爬取列表字段
    """
    default_output_processor = TakeFirst()

    # 帖子ID
    article_id = scrapy.Field(
        input_processor=MapCompose(get_nums),
        output_processor=default_output_processor
    )

    # 帖子type
    type_name = scrapy.Field(
        output_processor=default_output_processor
    )

    # 列表图片
    article_img = scrapy.Field(
        output_processor=default_output_processor
    )

    # 标题
    article_title = scrapy.Field(
        output_processor=default_output_processor
    )

    # 详情地址
    article_detailsSrc = scrapy.Field(
        output_processor=default_output_processor
    )

    # 详情包含图片数量
    article_imgCount = scrapy.Field(
        input_processor=MapCompose(get_nums),
        output_processor=default_output_processor
    )

    # 发稿时间
    article_sendTime = scrapy.Field(
        output_processor=default_output_processor
    )

    # 作者
    article_author = scrapy.Field(
        output_processor=default_output_processor
    )

    # 阅读量
    article_readCount = scrapy.Field(
        input_processor=MapCompose(get_nums),
        output_processor=default_output_processor
    )

    # 评论量
    article_commentsCount = scrapy.Field(
        input_processor=MapCompose(get_nums),
        output_processor=default_output_processor
    )

    # 点赞量
    article_likeCount = scrapy.Field(
        input_processor=MapCompose(get_nums),
        output_processor=default_output_processor
    )

    # 描述
    article_note = scrapy.Field(
        output_processor=default_output_processor
    )

    # 标签
    article_tag = scrapy.Field(
        # output_processor=default_output_processor
        output_processor=Join(",")
    )

    # 创建时间
    createTime = scrapy.Field(
        output_processor=default_output_processor
    )


class ScrapyDetailsItem(scrapy.Item):
    """
    爬取列表字段
    """
    default_output_processor = TakeFirst()

    # 帖子ID
    article_id = scrapy.Field(
        input_processor=MapCompose(get_nums),
        output_processor=default_output_processor
    )

    # 图片
    article_img = scrapy.Field(
        output_processor=default_output_processor
    )

    # 文案
    article_text = scrapy.Field(
        output_processor=default_output_processor
    )

    # 创建时间
    createTime = scrapy.Field(
        output_processor=default_output_processor
    )
